package com.gasolinator.a;

import com.gasolinator.a.app.helper.JsonUtils;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

/**
 * Created by IntelliJ IDEA.
 * User: fjhidalgo
 * Date: 18/12/11
 * Time: 20:20
 * To change this template use File | Settings | File Templates.
 */
public class JsonUtilsTest {
    private String dummyJson = "[{\"GasolineraId\":\"1\"},{\"GasolineraId\":\"2\"},{\"GasolineraId\":\"3\"}]";

    @DataProvider(name="json")
    Object[][] getJsons(){
        return new Object[][]{
                {1,true,"[]","[{\"GasolineraId\":\"1\"}]"},
                {1,false,dummyJson,"[{\"GasolineraId\":\"2\"},{\"GasolineraId\":\"3\"}]"},
                {2,false,dummyJson,"[{\"GasolineraId\":\"1\"},{\"GasolineraId\":\"3\"}]"},
                {3,false,dummyJson,"[{\"GasolineraId\":\"1\"},{\"GasolineraId\":\"2\"}]"},
                {1,true,"[{\"GasolineraId\":\"1\"}]","[{\"GasolineraId\":\"1\"}]"},
                {1,false,"[{\"GasolineraId\":\"1\"}]","[]"},

        };
    }
    @Test(dataProvider="json")
    public void testGetUpdatedFavoritesJson(Integer gasStationId, boolean active, String favs, String expected) throws Exception {
        String actual = JsonUtils.getUpdatedFavoritesJson(gasStationId, active, favs);
        Assert.assertEquals(actual,expected,"json is not well updated");
    }

    @DataProvider(name="json2")
    Object[][] getJsons2(){

        return new Object[][]{
                {1,"[]",0},
                {1,dummyJson,1}, // J
                {2,dummyJson,2},
                {3,dummyJson,3},
                {4,dummyJson,0},
        };
    }
    @Test(dataProvider="json2")
    public void testIsGasIdInFavorites(Integer gasStationId, String favs, Integer expected) throws Exception {
        Integer actual = JsonUtils.isGasIdInFavorites(gasStationId, favs);
        Assert.assertEquals(actual,expected,"look up for gasolineraid in json is not working");
    }

}
